/*
 * Copyright (c) 2014 laidian. All Rights Reserved.
 * 
 * @author yaoyuming
 * 
 * @date 2020-05-06 14:23
 */
package com.yao.fin.baidu;

import org.springframework.stereotype.Service;

import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @author yaoyuming
 * @date 2020/05/06 14:23
 */
@Service
@Slf4j
public class OcrSerivceImpl implements OcrSerivce {

    @Override
    public String general(String image) {

        JSONObject map = JSONUtil.createObj();

        map.put("image", image);
        map.put("paragraph", true);
        String token = BaiduRedisUtils.getToken();

        String generalUrl = BaiduApiConst.ACCURATE_BASIC + "?access_token=" + token;

        String result = HttpRequest.post(generalUrl).header(Header.CONTENT_TYPE, "application/x-www-form-urlencoded")
            .form(map).timeout(5000).execute().body();

        log.info("请求链接：{} ;;; 返回结果:{}", generalUrl, map, result);

        return result;
    }
}